/*
 * @Author: chenhuanhuan 2925102113@qq.com
 * @Date: 2024-03-13 15:54:54
 * @LastEditors: chenhuanhuan 2925102113@qq.com
 * @LastEditTime: 2024-11-22 21:44:35
 * @FilePath: \liuyanggui\src\api\business\user\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { getApi, postApi, service } from "../../config/request";
import { AxiosPromise } from "axios";
import { TokenInfo, LoginData, tokenData } from "./types";

// 登录
export const getLogin = (params: LoginData): AxiosPromise<tokenData> => {
  return postApi("/system/auth_user/login", params, {
    "Content-Type": "application/x-www-form-urlencoded",
  });
};

// 根据token获取用户信息
export function reqUserinfo(params: object = {}): AxiosPromise<TokenInfo> {
  return getApi("/system/auth_user/token_info", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 登出
export function reqLogout(params: object = {}): AxiosPromise {
  return postApi("/system/auth_user/login_out", params);
}

// 查询用户详情
export function reqUserDetail(params: object = {}): AxiosPromise<TokenInfo> {
  return getApi("/system/auth_user/get_one", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 查询用户列表
export function reqUserList(params: object = {}): AxiosPromise<TokenInfo> {
  return postApi("/system/auth_user/query_list", params);
}

// 修改用户信息
export function reqModifyUserInfo(params: object = {}): AxiosPromise {
  return postApi("/system/auth_user/modify", params);
}

// 添加用户
export function reqAddUser(params: object = {}): AxiosPromise {
  return postApi("/system/auth_user/save", params);
}

// 查询用户详情
export function reqUserInfo(params: object = {}): AxiosPromise<TokenInfo> {
  return getApi("/system/auth_user/get_one", {
    params,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  });
}

// 重置密码
export function reqResetPsd(params: object = {}): AxiosPromise {
  return postApi("/system/auth_user/reset_password", params);
}

// 分配角色给用户
export function reqAssignRole(params: object = {}): AxiosPromise {
  return postApi("/system/user_role/save", params);
}

// 启用-禁用
export function reqSwitchStatus(params: object = {}): AxiosPromise {
  return postApi("/system/auth_user/reset_status", params);
}

// 上传用户头像
export function upUserAvatar(params: object = {}): AxiosPromise {
  return postApi("/system/oss/uploadFacePic", params, {
    "Content-Type": "multipart/form-data",
  });
}
